using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace Animoso.Domain
{
    /// <summary>
    /// Een bestuursperiode van Animoso.
    /// </summary>
    public class Administration : DomainObject
    {
        public virtual IList<Member> Members { get; set; }

        public virtual DateTime StartDate { get; set; }
        public virtual DateTime? EndDate { get; set; }

        /// <summary>
        /// Pad naar bestuursfoto
        /// </summary>
        public virtual string Picture { get; set; }

        public void AddMember(Member member)
        {
            if (member.Role == Role.HeadChairman)
            {
                if (Members.Count(m => m.Role == Role.HeadChairman) >= 1)
                    throw new AnimosoException("There can be only one HeadChairman");
            }
            if (member.Role == Role.Treasurer)
            {
                if (Members.Count(m => m.Role == Role.HeadChairman) >= 1)
                    throw new AnimosoException("There can be only one Treasurer");
            }
            if (member.Role == Role.Chairman && member.Commission == null)
            {
                throw new AnimosoException("Chairman must have an commission");
            }

            Members.Add(member);
        }
    }
}